package com.captainbank.tcl.tclapplication.application;

import android.database.sqlite.SQLiteDatabase;
import android.support.multidex.MultiDexApplication;

import com.captainbank.tcl.tclapplication.model.DaoMaster;
import com.captainbank.tcl.tclapplication.model.DaoSession;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;

import cn.jiguang.share.android.api.JShareInterface;
import cn.jiguang.share.android.api.PlatformConfig;
import cn.magicwindow.MWConfiguration;
import cn.magicwindow.MagicWindowSDK;

/**
 * Created by TCL on 2019/4/3.
 * Describe:
 */
public class TclApplication extends MultiDexApplication {
    private static RefWatcher sRefWatcher;
    private static DaoSession daoSession;

    @Override
    public void onCreate() {
        super.onCreate();

//        initMW();//魔窗
//        initLeakCanary();//LeakCanary
        initJGShare();
        //配置greendao数据库
        initGreenDAO();
    }

    private void initGreenDAO() {
        //创建数据库tcl.db
        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "tcl.db", null);
//        DaoMaster.DevOpenHelper helper1 = new DaoMaster.DevOpenHelper(this, "tcl.db");
        //获取可写数据库
        SQLiteDatabase db = helper.getWritableDatabase();
//        SQLiteDatabase db = helper.getEncryptedReadableDb("tangcl");//加密数据库（tangcl为加密密码）
        //获取数据库对象
        DaoMaster daoMaster = new DaoMaster(db);
        //获取Dao对象管理者
        daoSession = daoMaster.newSession();
    }

    public static DaoSession getDaoSession() {
        return daoSession;
    }

    private void initLeakCanary() {
        sRefWatcher = LeakCanary.install(this);
    }

    public static RefWatcher getRefWatcher() {
        return sRefWatcher;
    }

    //初始化极光分享
    private void initJGShare() {
        JShareInterface.setDebugMode(true);//(调试模式)init接口之前调用
        PlatformConfig platformConfig = new PlatformConfig()
//                .setWechat("wxc40e16f3ba6ebabc", "dcad950cd0633a27e353477c4ec12e7a")
                .setQQ("1108805937", "gTbzBI17jyddCDks")
//                .setSinaWeibo("374535501", "baccd12c166f1df96736b51ffbf600a2", "https://www.jiguang.cn")
//                .setFacebook("1847959632183996", "JShareDemo")
//                .setTwitter("fCm4SUcgYI1wUACGxB2erX5pL", "NAhzwYCgm15FBILWqXYDKxpryiuDlEQWZ5YERnO1D89VBtZO6q")
//                .setJchatPro("1847959632183996")
                ;
        JShareInterface.init(this, platformConfig);
//        JShareInterface.init(this);
    }

    //初始化魔窗
    private void initMW() {
        MWConfiguration config = new MWConfiguration(this);
        config.setLogEnable(true);//打开极光魔链Log信息
        MagicWindowSDK.initSDK(config);
    }
}
